home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus 1999 #2 / Amiga Plus CD - 1999 - No. 2.iso / System-Boost / Workbench / Archive / PP_v1.4 / Source / asmsup.c next >
Text File  |  1998-11-08  |  3KB  |  92 lines

  1. /* asmsup.c
  2. **
  3. ** This is the assembler support code used by PP. It contains code for
  4. ** patching the DOS library. Context sensitivity has been added since
  5. ** v1.1 - these routines now act differently when running under DOS2.0
  6. **
  7. ** Shareware 1991, Copyright (C) 1991 by Michael Berg
  8. */
  9.  
  10. #asm
  11. DOSLibPatch    MACRO
  12.         public    _Real\1
  13.         public    _New\1
  14.         public    _Make\1
  15.         public    _Rest\1
  16.         public    _Check\1
  17.         public    _LVO\1
  18.         public    \2
  19.  
  20. _Make\1        movem.l    a6/d0-d2,-(sp)        ;save registers
  21.         move.l    \2,a6            ;store DOSBase in a6
  22.         movem.w    _LVO\1(a6),d0-d2    ;get the 3-word original seq.
  23.         movem.w    d0-d2,Orig\1        ;save these words
  24.         cmp.w    #$4ef9,d0        ;determine state of DOS vect.
  25.         bne.s    1$            ;original 1.2/1.3 DOS code
  26.  
  27.         lea    _Real\1,a0        ;takes care of 2.0/already
  28.         move.l    _LVO\1+2(a6),d0        ;patched code. Get the JMP
  29.         move.l    d0,4(a0)        ;target and create our own
  30.         move.w    #$4e71,(a0)        ;little code stub. 4e71='NOP'
  31.         lea    _New\1,a0        ;(we will not be needing the
  32.         move.l    a0,d0            ;moveq)
  33.         move.l    d0,_LVO\1+2(a6)
  34.         bra.s    2$
  35.  
  36. 1$        lea    _LVO\1(a6),a6
  37.         moveq    #0,d0
  38.         lea    _Real\1,a0
  39.         move.w    (a6),(a0)    ;fetch the 'moveq #?,d0' opcode
  40.         move.w    4(a6),d0    ;fetch the 'bra' offset
  41.         add.l    a6,d0        ;add to find branch target
  42.         addq.l    #4,d0        ;pc relative offset compensation
  43.         move.l    d0,4(a0)    ;we need this so we can jump directly
  44.         move.w    #$4ef9,(a6)    ;initiate new sequence: jmp $abs_addrs
  45.         move.l    #_New\1,2(a6)    ;jump to our new function, of corz!
  46. 2$        movem.l    (sp)+,a6/d0-d2    ;restore regs
  47.         rts
  48.  
  49. _Real\1        moveq    #0,d0        ;moveq value will be ajusted
  50.         jmp    $fffffe        ;the JMP address will be fixed
  51.  
  52.         dseg
  53. Orig\1        dc.w    0,0,0
  54.         cseg
  55.  
  56. _Check\1    moveq    #0,d0
  57.         move.l    \2,a0
  58.         move.l    _LVO\1+2(a0),d1
  59.         lea    _New\1,a0
  60.         cmp.l    d1,a0
  61.         sne    d0
  62.         rts
  63.  
  64. _Rest\1        move.w    d2,-(sp)
  65.         move.l    \2,a0
  66.         movem.w    Orig\1,d0-d2
  67.         movem.w    d0-d2,_LVO\1(a0)
  68.         move.w    (sp)+,d2
  69.         rts
  70.         ENDM
  71.  
  72. ;DOSLibPatch is a macro which defines four functions. For Open(), they are:
  73. ;
  74. ;MakeOpen    - Patch the DOS library Open() vector
  75. ;RestOpen    - Restore the DOS library to it's original state
  76. ;RealOpen    - This calls the original DOS function
  77. ;CheckOpen    - Returns 0 if the Open patch is still in function
  78. ;
  79. ;Furthermore, you yourself have to create a function called (in this case)
  80. ;NewOpen, with a parameter specification like Open(). Future calls to Open
  81. ;will be redirected to NewOpen. NewOpen has access to the original DOS code
  82. ;through the function RealOpen. RealOpen should also be defined like Open.
  83. ;Note that this macro is sensitive to its environment. Versions 1.2 and
  84. ;1.3 of the OS has this weird looking DOS library, where 2.0 has had its
  85. ;DOS library normalized to conform to the appearance of the other libraries.
  86.  
  87.         DOSLibPatch Open,_DOSBase
  88.         DOSLibPatch Close,_DOSBase
  89.         DOSLibPatch Examine,_DOSBase
  90.         DOSLibPatch Write,_DOSBase
  91. #endasm
  92.